<html>
<head><meta charset="utf-8"><title>move/init analysis for visualization · t-compiler/wg-polonius · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/index.html">t-compiler/wg-polonius</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html">move/init analysis for visualization</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246374424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246374424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Haochen Zhang <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246374424">(Jul 18 2021 at 12:10)</a>:</h4>
<p>Hi Polonius team! I'm an undergrad working with University of Michigan's Fp_lab Rustviz project to visualize rust programs for better user experience. Here's a demo: <a href="http://fplab.eecs.umich.edu:8000/">http://fplab.eecs.umich.edu:8000/</a> Essentially we are detecting where variables are borrowed and returned, initialized and dropped to generate corresponding visulization that could assist user in debugging their program. I've heard that <span class="user-mention" data-user-id="204115">@Amanda Stjerna</span> had done some work regarding moves and inits in polonius. Right how I'm quite new to rustc and polonius repo and I'd like to know more details of how and where they are implemented (and how could I improve it). If anyone could help point out where I could find these info that would be great help!</p>



<a name="246378891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246378891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246378891">(Jul 18 2021 at 13:30)</a>:</h4>
<p>Amanda can provide more answers but I can at least share some details about the "where" question:</p>
<ul>
<li>the rules describing the move/init analysis are in <a href="https://hackmd.io/CGMNjt1hR_qYtsR9hgdGmw?view#Initialization-analysis">this document</a>. There's often a short explanation of some of its parts to introduce how a relation is computed.</li>
<li>the polonius implementation (and I don't know the status wrt the rules above, I only remember it was still a work in progress) is in <a href="https://github.com/rust-lang/polonius/blob/master/polonius-engine/src/output/initialization.rs">this file</a> </li>
<li>the facts that are used in these rules are generated in rustc, and the areas where facts are generated are generally tracked in the self-profiler with the <code>polonius_fact_generation</code> task. So <a href="https://github.com/rust-lang/rust/search?q=polonius_fact_generation">searching for that</a> will find where  the code to generate these facts starts. The inputs themselves are described in the hackmd and code above, and can then be found in these <code>polonius_fact_generation</code> blocks: rustc fills the fields of <a href="https://github.com/rust-lang/polonius/blob/a4b3684aea9add867c60b9509891b10d7a74f189/polonius-engine/src/facts.rs#L6-L90">the <code>AllFacts</code> "database" struct</a> where the fields are named according to the relations that the rules expect</li>
</ul>



<a name="246392745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246392745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246392745">(Jul 18 2021 at 18:52)</a>:</h4>
<p>I remember there was a discussion about how to visualize this data on internals a while back. I think there was some good work on mockups for the front end, but the back end never happened. There are a lot of people that will love to see any progress you make!</p>



<a name="246502610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246502610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vytautas Astrauskas [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246502610">(Jul 19 2021 at 19:33)</a>:</h4>
<p>In case you want to bridge Polonius information with MIR, you may find <a href="https://github.com/rust-lang/rust/pull/86977">my PR</a> useful. The comment contains a link to the Prusti code that shows how to use it. If you have any questions, let me know.</p>



<a name="246503642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246503642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246503642">(Jul 19 2021 at 19:41)</a>:</h4>
<p>nice !</p>



<a name="246504561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246504561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246504561">(Jul 19 2021 at 19:48)</a>:</h4>
<p>Nice, improvising Rust visualization is indeed an approach that many beginners will be thankful to have <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>
<p>A nit, though: in the following diagram, I'd change the line for <code>z</code> to start at the end of the rhs block, since that's only when <code>z</code> starts living: <a href="/user_uploads/4715/fQMQN_U6FRIqQBu5_deGYszq/Screen-Shot-2021-07-19-at-21.46.27.png">Screen-Shot-2021-07-19-at-21.46.27.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/fQMQN_U6FRIqQBu5_deGYszq/Screen-Shot-2021-07-19-at-21.46.27.png" title="Screen-Shot-2021-07-19-at-21.46.27.png"><img src="/user_uploads/4715/fQMQN_U6FRIqQBu5_deGYszq/Screen-Shot-2021-07-19-at-21.46.27.png"></a></div>



<a name="246835647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246835647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Haochen Zhang <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246835647">(Jul 22 2021 at 11:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232018">Daniel Henry-Mantilla</span> <a href="#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/move.2Finit.20analysis.20for.20visualization/near/246504561">said</a>:</p>
<blockquote>
<p>Nice, improvising Rust visualization is indeed an approach that many beginners will be thankful to have <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>
<p>A nit, though: in the following diagram, I'd change the line for <code>z</code> to start at the end of the rhs block, since that's only when <code>z</code> starts living: <a href="/user_uploads/4715/fQMQN_U6FRIqQBu5_deGYszq/Screen-Shot-2021-07-19-at-21.46.27.png">Screen-Shot-2021-07-19-at-21.46.27.png</a></p>
</blockquote>
<p>Hi Daniel! Thanks for the interest in the work! Could you specify what do you mean by the end of the rhs block?</p>



<a name="246836234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246836234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Haochen Zhang <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246836234">(Jul 22 2021 at 11:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120179">Eh2406</span> <a href="#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/move.2Finit.20analysis.20for.20visualization/near/246392745">said</a>:</p>
<blockquote>
<p>I remember there was a discussion about how to visualize this data on internals a while back. I think there was some good work on mockups for the front end, but the back end never happened. There are a lot of people that will love to see any progress you make!</p>
</blockquote>
<p>Thanks! We definitely noticed some really nice front-end mock-ups works regarding data visualization. I'm guessing you are probably refering to this one: <a href="https://blog.adamant-lang.org/2019/rust-lifetime-visualization-ideas/">https://blog.adamant-lang.org/2019/rust-lifetime-visualization-ideas/</a> Our goal is to eventually auto-gen all the visualization and integrate them to tools like VSCode</p>



<a name="246950147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/246950147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Haochen Zhang <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#246950147">(Jul 23 2021 at 08:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="421546">Haochen Zhang</span> <a href="#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/move.2Finit.20analysis.20for.20visualization/near/246835647">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="232018">Daniel Henry-Mantilla</span> <a href="#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/move.2Finit.20analysis.20for.20visualization/near/246504561">said</a>:</p>
<blockquote>
<p>Nice, improvising Rust visualization is indeed an approach that many beginners will be thankful to have <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>
<p>A nit, though: in the following diagram, I'd change the line for <code>z</code> to start at the end of the rhs block, since that's only when <code>z</code> starts living: <a href="/user_uploads/4715/fQMQN_U6FRIqQBu5_deGYszq/Screen-Shot-2021-07-19-at-21.46.27.png">Screen-Shot-2021-07-19-at-21.46.27.png</a></p>
</blockquote>
<p>Hi Daniel! Thanks for the interest in the work! Could you specify what do you mean by the end of the rhs block?</p>
</blockquote>
<p>Should be fixed. Seems only to support on firefox for now</p>



<a name="247400466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/247400466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#247400466">(Jul 27 2021 at 22:26)</a>:</h4>
<p><span class="user-mention silent" data-user-id="421546">Haochen Zhang</span> <a href="#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/move.2Finit.20analysis.20for.20visualization/near/246835647">said</a>:</p>
<blockquote>
<p>Hi Daniel! Thanks for the interest in the work! Could you specify what do you mean by the end of the rhs block?</p>
</blockquote>
<p>Lines 3 to 7 is a block (right hand side of the declaration) defining the value of z, the left hand side of the declaration. So the declaration and assignment of <code>z</code> only truly takes place from line 7 onwards:</p>
<p><a href="/user_uploads/4715/Ue9Zxhbwk7n4jjD-o6iknJZj/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/Ue9Zxhbwk7n4jjD-o6iknJZj/image.png" title="image.png"><img src="/user_uploads/4715/Ue9Zxhbwk7n4jjD-o6iknJZj/image.png"></a></div><p>That's why I suggest that the lifetime of <code>z</code> be trimmed so that it only starts at line 7 <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="247400782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/247400782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#247400782">(Jul 27 2021 at 22:30)</a>:</h4>
<p>it's been done indeed <a href="/user_uploads/4715/UmiADm8YxHtQ5ymXpOsRFCr7/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/UmiADm8YxHtQ5ymXpOsRFCr7/image.png" title="image.png"><img src="/user_uploads/4715/UmiADm8YxHtQ5ymXpOsRFCr7/image.png"></a></div>



<a name="247400852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/186049-t-compiler/wg-polonius/topic/move/init%20analysis%20for%20visualization/near/247400852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/186049-t-compiler/wg-polonius/topic/move.2Finit.20analysis.20for.20visualization.html#247400852">(Jul 27 2021 at 22:31)</a>:</h4>
<p>(modulo the off-by-one on the last line, say :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>